package bb.lanxing.lib.devices.core.sync;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class SyncManagerHolder {
    private Map<String, SyncManager> syncManagerMap;

    public SyncManagerHolder(SyncManager... syncManagerArr) {
        if (syncManagerArr != null) {
            for (SyncManager syncManager : syncManagerArr) {
                addSyncManager(syncManager);
            }
        }
    }

    public boolean hasSyncManager(String str) {
        Map<String, SyncManager> map = this.syncManagerMap;
        return map != null && map.containsKey(str);
    }

    public SyncManager getSyncManger(String str) {
        if (!(str == null && this.syncManagerMap == null) && !this.syncManagerMap.isEmpty()) {
            if (str == null) {
                Iterator<String> it = this.syncManagerMap.keySet().iterator();
                if (!it.hasNext()) {
                    return null;
                }
                return this.syncManagerMap.get(it.next());
            }
            return this.syncManagerMap.get(str);
        }
        return null;
    }

    public void addSyncManager(SyncManager syncManager) {
        if (this.syncManagerMap == null) {
            this.syncManagerMap = new HashMap();
        }
        this.syncManagerMap.put(syncManager.getClass().getName(), syncManager);
    }

    public void removeSyncManager(String str) {
        Map<String, SyncManager> map = this.syncManagerMap;
        if (map != null) {
            map.remove(str);
        }
    }

    public Iterator<SyncManager> iterator() {
        if (this.syncManagerMap != null) {
            return new ArrayList(this.syncManagerMap.values()).iterator();
        }
        return null;
    }
}
